<template>
    <t-modal :title="$ct('edit','编辑')" :width="600" :visible="visible" :switchFullscreen="true"
             :confirmLoading="loading" @ok="() => {$emit('ok');}" @cancel="() => {$emit('cancel');}">
        <a-spin :spinning="loading">
            <a-form :form="form">
                <a-row>
                    <a-form-item class="hiddenItem">
                    <!-- uuid隐藏 -->
                    <a-input v-decorator="['uuid']" disabled type="hidden" />
                    </a-form-item>
                    <a-col :span="24">
                        <a-form-item :label="$ct('defaultPackageName','默认包名')" :labelCol="labelCol"
                                     :wrapperCol="wrapperCol" placeholder="">
                            <a-input v-decorator="['packageName',{ rules: [{ required: true, message: '请输入默认包名' }]}]"/>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :label="$ct('systemModule','系统模块')" :labelCol="labelCol"
                                     :wrapperCol="wrapperCol" placeholder="">
                            <a-input v-decorator="['moduleName',{ rules: [{ required: true, message: '请输入系统模块' }]}]"/>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :label="$ct('defaultAuthor','默认作者')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['author',{ rules: [{ required: true, message: '请输入默认作者' }]}]"/>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :label="$ct('authorEmail','作者邮箱')" :labelCol="labelCol"
                                     :wrapperCol="wrapperCol" placeholder="">
                            <a-input v-decorator="['mailbox',{ rules: [{ required: true, message: '请输入作者邮箱' }]}]"/>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :label="$ct('defaultVersionNumber','默认版本号')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['version',{ rules: [{ required: true, message: '请输入默认版本号' }]}]"/>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </a-spin>
    </t-modal>
</template>

<script>
    import pick from "lodash.pick";
    const fields = [
        'uuid',
        'packageName',
        'moduleName',
        'author',
        'version',
        'mailbox'
    ];
    export default {
        props: {
            visible: {
                type: Boolean,
                required: true,
            },
            loading: {
                type: Boolean,
                default: () => false,
            },
            model: {
                type: Object,
                default: () => null,
            },
            visible:{
                type: Boolean,
                default: false,
            }
        },
        data() {
            return {
                title: "",
                labelCol: {
                    xs: {
                        span: 24,
                    },
                    sm: {
                        span: 5,
                    },
                },
                wrapperCol: {
                    xs: {
                        span: 24,
                    },
                    sm: {
                        span: 16,
                    },
                },
                formData: [],
                form: this.$form.createForm(this),
                // title:'编辑'
            }

        },
        comments:{
            pick
        },
        methods: {
            add(m, data) {
                // console.log(m, data);
            },
            edit(m, data) {
                // console.log(m, data);
            },
            callback(key) {
                // console.log(key);
            },
        },
        created() {
            // 防止表单未注册
            fields.forEach((v) => this.form.getFieldDecorator(v));
            // 当 model 发生改变时，为表单设置值
            this.$watch("model", () => {
                this.model && this.form.setFieldsValue(pick(this.model, fields));
            });
        },
    };

</script>
